David Karlins
Congratulations! You've made it to Lesson 12, and you have just one more lesson to go before you can take your final exam. In this final lesson, you'll learn to enhance jQuery Mobile Web apps with custom-defined themes using ThemeRoller—a great, and free, online resource.
If you have any questions as you prepare for the final exam, please post them in the Discussion Area. And if you're interested in furthering your study of advanced Web page design, I encourage you to check into the Introduction to JavaScript course offered in your catalog.
It's been great having you with us for this course, and I wish all of you the best in everything you do with advanced Web page design using HTML and CSS3!
end transcript
Introduction
In the previous lesson, you created basic Web apps with jQuery Mobile. Now you know how to use the basic building blocks to create a mobile site that works well. What's missing, though, is style.
Unlike "normal" Web pages, when it comes to creating jQuery Mobile pages, the CSS file is already built for us. It's huge. It's complex. And if we mess with it, the whole jQuery Mobile framework of interconnected JavaScript and CSS can easily become corrupt.
Does that mean that you're stuck with jQuery Mobile sites constrained to a few primary colors? Thankfully, no. You can define distinctive themes and colors for your jQuery site using a CSS generator resource called ThemeRoller. ThemeRoller is free and open source, although Adobe has bought it.
Defining custom themes in ThemeRoller
This isn't the first time that we've used an online resource to generate complex CSS. Back in Lesson 4 we used an online resource, the Ultimate CSS Gradient Generator, to generate linear and radial CSS3 gradient backgrounds.
Linear and radial CSS3 backgrounds
I'm reviewing our experience with the Ultimate CSS Gradient Generator for a couple of reasons. One is to note a pattern of finding online resources to save time and stress in creating complex CSS3. The other reason is that much of what we'll do when we create custom CSS for jQuery Mobile sites is to generate different background gradients for jQuery Mobile elements (including page, listview, content, header, and footer).
We'll also use Adobe Kuler again. Remember that online resource? We used it to create color schemes back in Lesson 3. I'll remind you of the basics of Kuler when we set up color swatches for our theme in Chapter 2 of this lesson.
I wanted to save an especially fun lesson for our final lesson. And ThemeRoller is fun. By the time we complete this lesson, your mobile site will be as distinctive and colorful as you want it to be!
How Themes and Swatches Work
Before we head over to the ThemeRoller site to create custom CSS, let's quickly review the relationship between themes and swatches in jQuery Mobile. The terminology is confusing, so let's sort through it:
Themes actually have two parts. The global part defines fonts, border radii, and drop shadows no matter what color swatch you're using. And the swatch is the data-theme color set (a through e).
So when we head over to the jQuery Mobile site to define custom themes, we'll create global theme styling and define specific color swatches.
By the way, we aren't limited to five color swatches. You can create as many as 26 color swatches in ThemeRoller.
Supported Browsers
The jQuery Mobile ThemeRoller resource we'll use in this lesson works with the latest versions of desktop and laptop browsers. That means:
Other browsers don't work reliably to generate themes. What about the current version of Internet Explorer? At this writing, the jQuery Mobile ThemeRoller site doesn't recommend using it.
If you haven't installed Chrome, Firefox, or Safari by now, this is the moment to do so. You can install Chrome from www.google.com/chrome, and you can install Firefox from http://www.mozilla.org/en-US/firefox/new/. (If you're a Windows user, it's possible for you to download Safari, but you may need to use an older version with fewer features than the ones that Mac users have.)
Using the Right ThemeRoller
To design custom themes for jQuery Mobile sites, launch your browser if it isn't already open, and head over to the ThemeRoller jQuery Mobile site at http://jquerymobile.com/themeroller.
Careful! Do not head over to the ThemeRoller jQuery UI site at jqueryui.com/themeroller. That site generates themes for jQuery widgets, like the slide-show jQuery widget we created in Lesson 10. (UI stands for user interface.) If you search for "ThemeRoller," you'll find links to this site at the top of the list, but it isn't what we want.
To add to the confusion, the two ThemeRoller sites look something alike. But if you see a page that starts "jQuery User Interface ThemeRoller," you've made a wrong turn. The themes you find at jqueryui.com/themeroller don't work with jQuery Mobile sites.
The jQuery ThemeRoller User site, which doesn't work with jQuery Mobile
By the way, are you wondering why we didn't explore themes when we created jQuery Mobile widgets in Lesson 10? The answer is that themes aren't essential for styling jQuery widgets. As we saw in Lesson 10, it wasn't hard to define our own CSS for a jQuery widget.
So double-check: You're at http://jquerymobile.com/themeroller, right? You should see a dialog box with the title "Welcome to ThemeRoller for jQuery Mobile." Click Get Rolling.
Getting rolling at the jQuery Mobile ThemeRoller site
Exploring the jQuery Mobile ThemeRoller Interface
The interface has four main regions:
Theme and swatch panels
Preview pane
QuickSwatch/Kuler bar
Tools for generating CSS code
We'll spend the bulk of this chapter in the left panel, defining themes and swatches and observing the effects in the preview pane. But first let's look at the QuickSwatch/Kuler bar.
Setting Up Swatch Colors
As I mentioned back in Lesson 3, Kuler is Adobe's online tool for generating color schemes. You can use the slimmed-down version of Kuler in the ThemeRoller for jQuery Mobile interface to get help generating your own color scheme.
Remember color schemes? You might want to jump back to Lesson 3 for a quick review. That's where we explored Kuler. I won't review all that here, but remember that we used Kuler to pick five colors that would be the base of our site's color scheme.
Even if you have a defined color scheme for your regular site, you might choose a different set of five colors for your mobile color scheme. Remember, mobile devices generally don't have the powerful backlighting that desktop and laptop computers have. And people often view mobile devices in bright light. So you might want a high-contrast color scheme for your mobile site.
To get help from Kuler, click the expand icon that's next to the Adobe Kuler swatches link in the QuickSwatch/Kuler bar.
Expanding the Kuler Swatches panel
Use the Search box in the Kuler panel to explore ideas for color scheme sets. Click on any color to add it to the easily accessible set of Recent Colors in the QuickSwatch/Kuler bar. You can select all five colors in any Kuler color scheme this way.
Choosing colors from a Kuler scheme
You can also close the Kuler panel and define colors using a color wheel or CSS hexadecimal values. Just click the colors link.
Defining colors from a color wheel
With your color swatch bar loaded up with the colors you'll be using, you're ready to define global theme elements as well as a set of swatches. We'll do that in the next chapter.
Defining a Custom Global Theme
Remember, themes are composed of global elements as well as specific swatch color schemes. Here's the full set of global theme elements.
Defining Gradients
Update note: As of version 1.4.1, jQuery Mobile ThemeRoller dropped the ability to easily define gradients. To "re-enable" this feature, choose Version 1.3.2 from the Switch to Version drop-down menu at the top of the jQuery Mobile ThemeRoller menu bar.
Switch to Version 1.3.2 to easily define gradients.
Update Note: jQuery Mobile ThemeRoller is constantly evolving, and different versions provide more, or fewer options for defining gradient backgrounds for different elements.
I mentioned that we would be generating CSS3 gradients as an integral part of creating custom themes. jQuery Mobile provides gradient generators in many panels. Since they work the same way in every panel, let's walk through how to use them.
When you define a background color in ThemeRoller, you have the option of making that background a gradient. But before you can see the gradient definition slider, you need to expand the Background swatch by clicking the "+" sign that's next to it.
Expanding a background color swatch
The color swatch will expand to show a Start button and an End button. Click Start. To define a start color, you can choose one from the color wheel, enter a hexadecimal value, or drag a color from the QuickSwatch/Kuler bar.
Defining a start color for a gradient background
Define an end color.
Defining an end color for a gradient background
Defining Global Theme Elements
As you define your global theme elements, you'll see them show up in all the visible swatch color preview panels on the right side of the ThemeRoller page. Among those elements, by the way, are fonts—the same set of fonts applies to your entire mobile site.
A Quick Note on Fonts
Earlier in the course, we explored Web fonts in detail. I'm not suggesting you need to review that, and we won't revisit the option of using downloadable Web fonts now. But if you want to revisit the basic concepts behind using fonts on the Web, you might find it helpful to review "Surveying and Selecting Web Fonts" in Lesson 4, Chapter 4.
Okay, with that said, follow these steps to define global theme elements:
Defining a font family
Defining an Active State display
Defining corner radii
Defining black icons with hidden discs
Defining drop shadows and testing their effect on listviews
Defining Custom Swatch A
The global theme elements that we just set created some coherent styling that will apply in every color swatch. But we can vary the colors of different elements by defining specific color swatches . . . up to 26 of them!
To define a first color swatch, follow these steps:
Selecting the A swatch tab
Customizing swatch A
a. The most important one is Content Body because that will define the color for the main part of the page. b. You can define link colors for each swatch. If you expand the Link Color box, you can define link colors for different states (regular, visited, active, and hovered). c. The three button states (normal, hover, and pressed) will apply to buttons such as the Back button. These are beyond the scope of this course, but you can see the previews as you define them. You can test the hover and pressed button states by hovering over or pressing on a button in the preview area.
a. The most important one is Content Body because that will define the color for the main part of the page.
b. You can define link colors for each swatch. If you expand the Link Color box, you can define link colors for different states (regular, visited, active, and hovered).
c. The three button states (normal, hover, and pressed) will apply to buttons such as the Back button. These are beyond the scope of this course, but you can see the previews as you define them. You can test the hover and pressed button states by hovering over or pressing on a button in the preview area.
Previewing hover state for a button
Defining Additional Swatches
In order to have a set of color options, you'll want to create additional custom color swatches. How many do you need? Probably three; that gives you a nice set of color options. But as I mentioned, you can create up to 26.
If you want to make your second swatch (B) a variation on the colors you applied to swatch A, you might want to start by duplicating Swatch A. Do that by clicking Duplicate.
Duplicating the A swatch tab
The duplicated swatch doesn't become Swatch B. Instead, it goes at the end of the default swatches and becomes Swatch D. If you want to make the duplicate swatch into Swatch B, select Swatch B, and click Delete. Do that again for Swatch C, and what was Swatch D becomes Swatch B.
Deleting the default B and C swatches
On your own, edit the colors in the B swatch, and then create at least a C swatch as well. If you have any trouble, please post a message in the Discussion Area.
Once you've finished, please join me in Chapter 4 to download and apply the theme you just created.
Rolling a jQuery Mobile Theme
Creating a custom jQuery Mobile theme with custom color swatches was fun and easy, right? Downloading and applying the theme is the more technical part. But we'll walk through that step by step.
jQuery Mobile generates a CSS file that replaces the default one. We'll need to link to that replacement CSS file in our jQuery Mobile site.
We have two ways to do that. One is to save and store the theme at the jQuery Mobile site. But your CSS file will only be stored there for a month, so that isn't a solution if you intend to use the theme in your site for an extended period.
The second and more useful option is to download the CSS as a Zipped file.
Linking to a jQuery Mobile Custom Theme
To download the Zipped file, follow these steps:
Downloading a Zip file
Naming the theme
<meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="css/themes/my-custom-theme.css" /> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile.structure-1.3.2.min.css" /> <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> <script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
Copying the <head> element HTML
Replacing links to jQuery Mobile CSS and JavaScript
<link rel="stylesheet" href="css/themes/my-custom-theme.css" />
to
<link rel="stylesheet" href="my-custom-theme.css" />
That was a lot of steps! So let me walk through the process in a video:
This is David Karlins, your instructor. And in this video I'm going to demonstrate how to download the theme that you defined in the jQuery Mobile ThemeRoller window into your site.
So creating the theme itself is kind of fun and intuitive in jQuery Mobile's ThemeRoller window. And I think you probably made your way through that without too much trouble. Having done that, the next step is to locate the Download button to give your theme a name. And I suggest "my-custom-theme" just like ThemeRoller does.
So make your theme name "my-custom-theme." And then download the Zip file that contains all the necessary files for your CSS.
The next step, which I won't walk through because it's going to be different for all of us, is to take the files that are in that Zip file and to copy and paste them into the root folder for your website.
So once you've done that—now I can go back into Dreamweaver and replace the code in my ...head... element with the code from jQuery Mobile ThemeRoller. Let me go back to jQuery Mobile ThemeRoller, hit the Download button again, and get the code. And all we really need to replace is the section of the code that's in the ...head... element.
So I'll copy it from jQuery Mobile ThemeRoller and replace the ...head... element content in my site with that site's. And of course I can customize things like my page title, which I've done here.
The other thing is that, because we copied the my-custom-theme file directly into the root folder of our site, we're going to change the path of the link to that CSS file so that it matches our site. And then when I refresh my screen, you can see over on the right— and I'll jump into Design view for a minute so you can see even more—that my custom theme got applied to the page.
Let's review what happened to connect our site to our custom theme.
We generated a Zip file, which included a CSS file that replaced the default jQuery Mobile CSS file with our own theme and color swatches. We downloaded that file (along with some other files we didn't need, like an index.html file that you could use to demonstrate how the theme looks).
We also grabbed five lines of code for the <head> element in our jQuery Mobile page. That code accomplished the following:
The jQuery Mobile ThemeRoller site made this process pretty easy, but I thought it was important to walk through exactly what happened . . . as a matter of principle and to help you troubleshoot in case a step or two didn't go quite right.
Applying Data Themes
Are we ready to test our default theme yet? Not quite! Let's first make sure we have defined data-themes for elements.
Remember, in order to apply a color swatch to any element in a jQuery Mobile page, you need to define a data-theme for that element. If you don't define a data-theme, then data-theme="b" will apply to an element by default.
To define a custom data theme for any element, edit the HTML for the data-theme= parameters to apply the swatches you created in ThemeRoller. For example, if you created only two swatches, "a" and "b," apply one of those two to each data-theme.
You should have data-theme parameters added to elements throughout your site. Here's a bit of example code:
<div data-role="page" id="page" data-theme="a"> <div data-role="header"> <h1>Page One</h1> </div> <div data-role="content" data-theme="b"> <ul data-role="listview" data-inset="true" data-theme="c"> <li><a href="#page2">Page 2</a></li> <li><a href="#page3">Page 3</a></li> <li><a href="#page4">Page 4</a></li> <li><a href="#page5">Page 5</a></li> </ul> </div> <div data-role="footer" > <h4>Page Footer</h4> </div> </div>
Save your page, and open it in a browser window. Of course your content and style will differ from mine, but you should see the theme and swatch elements you defined and applied in your browser.
Testing a custom theme
Inspecting the CSS
By creating a custom theme at ThemeRoller, we generated our own CSS file for jQuery Mobile. As I alluded to in the previous section, the CSS file we generated complements the central CSS file for jQuery Mobile; it doesn't replace the central file. We're still linking to a file at the jQuery Mobile Central Distribution Network—one that has a filename something like jquery.mobile.structure-1.3.2.min.css. That file has some of the required CSS that makes our jQuery Mobile site work.
But a good chunk of the CSS that makes our jQuery Mobile site look and act the way it does is now saved in our own site. (And by the way, if you upload your site to a server, be sure to upload the my-custom-theme.css file along with your edited site.)
Since the section of the CSS that defines our jQuery Mobile theme is now in our own site folder, it's easy to open and inspect in a code editor. You might want to try doing that. The CSS isn't commented (in other words, the code doesn't include explanatory text). But there are "---" comment lines that separate your swatch definitions. You can locate those and at least inspect the code.
Inspecting custom theme code
Summary
"Themes" is a buzzword these days. If you use a WordPress template to generate a blog or a website, you pick a theme that provides color and page layout styling.
In some ways, the theme that comes with jQuery Mobile plays a similar role. It provides a set of five color swatches as well as default styling for pages, headers, footers, content areas, and listviews.
ThemeRoller for jQuery Mobile allows us to break out of the constraints of the default theme and the default swatch color schemes. By the time we finish defining custom fonts, custom border radii, custom shadows for our theme, and custom colors and gradient backgrounds for our swatches, we can say that our jQuery Mobile sites are one-of-a-kind websites rather than customized templates.
ThemeRoller for jQuery Mobile: Part of a Universe of Free Web Design Resources
This is our last lesson (sigh! Where did the time go?). So I want to note that ThemeRoller for jQuery Mobile ThemeRoller is part of an emerging—and rather amazing—community of resources that support those of us who are in do-it-yourself Web design.
One of the things I hope you've gotten from this course is an appreciation for how substantial and useful that set of free online resources is. If you think back to previous lessons, we've used a wide range of free resources . . . starting with HTML5 and CSS3! Other free resources include:
With the HTML5 and CSS3 skills you've picked up and strengthened through this course, your potential as a designer is unlimited. You can connect the HTML5 and CSS3 you craft with a universe of free resources that do everything from generate search boxes to provide custom fonts.
Let me emphasize this point: If you have a solid grounding in HTML5 and CSS3 (and you do!), you're in the best possible position to exploit that universe of resources.
So . . . go forth and do that!
Final Steps
Now that you've finished the last lesson, is there anything else to do? Yes, several things!
Other Courses
If you enjoyed this course, here are a few other online courses you might be interested in:
Learn to build mobile-friendly websites for smartphones and tablets. You'll use Dreamweaver's menus and panels to generate animated, interactive navigation elements that rely on the jQuery Mobile library of code.
Introduction to JavaScript
Why should you learn JavaScript? If you want to do Web development work, you need to know it. The vast majority of Web pages out there contain some JavaScript code. Along with CSS and HTML, it's essential for Web developers.
Introduction to PHP and MySQL
Learn how to create an interactive Web site, allowing visitors to post and retrieve information provided by you or your site's visitors. In this six-week online course, you'll create dynamic Web pages using the PHP programming language and the MySQL database server.
I haven't found many jQuery Mobile theme templates, but here's one: The Metro style theme for JQuery Mobile is available for download.
I've provided a link to a Microsoft-inspired jQuery Mobile theme, so here's a link to a theme inspired by iOS, the Apple mobile operating system.
Check out these free themes for jQuery Mobile.
Q: Could we apply custom Web fonts like the ones we used in Lesson 4 to our jQuery Mobile custom themes?
A: Yes! When you define your theme in ThemeRoller, define your custom font as part of the theme. Add the link to the Google-hosted CSS file to your <head> element, just as we did in Lesson 4.
Q: Why would anyone need more than three jQuery Mobile swatches in a theme?
A: Given how hard it is to create CSS styles, you might use extra swatches to hold formatting styles like highlighting background colors or font colors. You could then use those extra swatches to apply a background color, or you could apply color to any element, such as a page footer. Q: I took your advice and examined the custom CSS file downloaded from jQuery Mobile ThemeRoller. I think I can edit this . . . is that dangerous?
A: No. I would save a backup copy of the file before editing. But the CSS in this file has been separated from some of the CSS that's critical to the jQuery Mobile site functioning, so you can edit it. If things go wrong, you can regenerate the file from the jQuery Mobile ThemeRoller site.
For our last lesson together, I'd like you to create and apply a custom theme for your site using jQuery Mobile ThemeRoller. Here's what that involves:
You're welcome to ask me questions in the Discussion Area if you're having trouble with this assignment or with anything in this course. It's been a pleasure having you in class!
Back to top